<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise</title>
</head>
<body>
    <script>
        let p1 = new Promise((resolve, reject)=>{
            resolve('成功01')
            console.log(1)
        })
        let p2 = new Promise((resolve, reject)=>{
            console.log(2)
            // resolve('成功02')
            setTimeout(()=>{
                reject('失败02')
            },100)
        })
        let p3 = new Promise((resolve, reject)=>{
            console.log(3)
            // resolve('成功03')
            setTimeout(()=>{
                reject('失败03')
            },50)
        })
        let pAll = Promise.all([p1,p2,p3])  //这步运行时, 已经执行了所有的promise
        console.log(pAll)
        pAll.then(res => {
            console.log(res)  // ['成功01','成功02','成功03']
        }).catch(err => {
            console.log(err)   // 如果有多个失败, 只返回第一个执行失败的结果  就是失败03
        })
        
        //Promise.race([p1,p2,p3])  //当打包的实例中有一个改变状态, 就返回那个值
    </script>
</body>
</html>